﻿<?php
    $username = $_POST['username'];
    $password1 = $_POST['password1'];
    $password2 = $_POST['password2'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $gender = $_POST['gender'];
    $location = $_POST['location'];
    $role = $_POST['role'];
    $phone1 = $_POST['phone1'];
    $phone2 = $_POST['phone2'];
    $email = $_POST['email'];
    $website = $_POST['website'];


if(isset($username)){//έλεγχος οτι έχει μπει όνομα χρήστη

    if($password1==$password2){//έλεγχος οτι τα δύο password είναι ίδια

        $password1 = md5($password1);//κρυπτογράφηση password

        $query = "INSERT INTO USERS (user_name, user_passwd, user_level, user_fname, user_lname, user_phone1, user_phone2, user_gender, user_email, user_website)
        VALUES ('".$username."', '".$password1."', ".$role.", '".$fname."', '".$lname."', '".$phone1."', '".$phone2."', '".$gender."', '".$email."', '".$website."')";

        $set->qry($query);

        include 'user_search.php';
        include 'user_results.php';

    }
}

else{
?>
<div id = "user_details">

    <div>
        <form action=<?php echo "users.php?action=new"?> method="post">

        <table class="table_search">
            <tr>
                <td>Username</td>
                <td><input id="username" class="search_input" type="text" name="username"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input id="password1" class="search_input" type="text" name="password1"></td>
            </tr>
            <tr>
                <td>Password Again</td>
                <td><input id="password2" class="search_input" type="text" name="password2"></td>
            </tr>
            <tr>
                <td>First name</td>
                <td><input id="fname" class="search_input" type="text" name="fname"></td>
            </tr>
            <tr>
                <td>Last name</td>
                <td><input id="lname" class="search_input" type="text" name="lname"></td>
            </tr>
            <tr>
                <td>Gender</td>
                <td><input id="gender" class="search_input" type="text" name="gender"></td>
            </tr>
            <tr>
                <td>Location</td>
                <td><textarea id="location" class="search_input" name="location" rows="5"></textarea></td>
            </tr>
            <tr>
                <td><label>User Role</label></td>
                <td><select id="role" class="search_input" type="text" name="role">
                <option value=1>Administrator</option>
                <option value=4 selected>Individual</option>
            </select> </td>
            </tr>
            <tr>
                <td>Phone 1</td>
                <td><input id="phone1" class="search_input" type="text" name="phone1"></td>
            </tr>
            <tr>
                <td>Phone 2</td>
                <td><input id="phone2" class="search_input" type="text" name="phone2"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input id="email" class="search_input" type="text" name="email"></td>
            </tr>
            <tr>
                <td>Web site</td>
                <td><input id="website" class="search_input" type="text" name="website"></td>
            </tr>
        </table>
        <table class="table_search">
            <tr>
                <td>
                    <input type="submit"  value="Save" id="save_btn">
                </td>
            </tr>
        </table>
    </div>
    </form>
</div>
<?php
}
?>